<html>
<head><meta charset="utf-8"><title>Get closure sig from `def_id` · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20closure.20sig.20from.20.60def_id.60.html">Get closure sig from `def_id`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244081601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20closure%20sig%20from%20%60def_id%60/near/244081601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20closure.20sig.20from.20.60def_id.60.html#244081601">(Jun 27 2021 at 19:40)</a>:</h4>
<p>Is it possible to get a closure's <code>PolyFnSig</code> given it's <code>DefId</code>? I'm trying to get the closure type with <code>tcx.type_of(def_id</code>), then then doing <code>closure_substs.as_closure().sig()</code>. However, it looks like the closure substs returned by <code>type_of</code> have a dummy signautre: <a href="https://github.com/rust-lang/rust/blob/9cdb2d3d59bad2843330535a41d0ebbb831fe57e/compiler/rustc_typeck/src/collect.rs#L1646">https://github.com/rust-lang/rust/blob/9cdb2d3d59bad2843330535a41d0ebbb831fe57e/compiler/rustc_typeck/src/collect.rs#L1646</a></p>



<a name="244083791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20closure%20sig%20from%20%60def_id%60/near/244083791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20closure.20sig.20from.20.60def_id.60.html#244083791">(Jun 27 2021 at 20:41)</a>:</h4>
<p>See the private Instance::fn_sig_for_fn_abi: <a href="https://github.com/rust-lang/rust/blob/a4f832b2755fa1421edd3bf6d8b4d61f2c1732b6/compiler/rustc_middle/src/ty/layout.rs#L2470">https://github.com/rust-lang/rust/blob/a4f832b2755fa1421edd3bf6d8b4d61f2c1732b6/compiler/rustc_middle/src/ty/layout.rs#L2470</a></p>



<a name="244083864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20closure%20sig%20from%20%60def_id%60/near/244083864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20closure.20sig.20from.20.60def_id.60.html#244083864">(Jun 27 2021 at 20:42)</a>:</h4>
<p>Why do you need it by the way?</p>



<a name="244091740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20closure%20sig%20from%20%60def_id%60/near/244091740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20closure.20sig.20from.20.60def_id.60.html#244091740">(Jun 28 2021 at 00:07)</a>:</h4>
<p>I'm working on adding track_caller support to closures, and I'm trying to adapt the reify shim mid generation for closures</p>



<a name="244091748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Get%20closure%20sig%20from%20%60def_id%60/near/244091748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Get.20closure.20sig.20from.20.60def_id.60.html#244091748">(Jun 28 2021 at 00:07)</a>:</h4>
<p>Which is needed when casting a track_caller closures to <code>&amp;dyn Fn</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>